import { getApiData, getApisData, getInitData, getNestApiData, getNestTeApiData } from "@/services/cpasRequest";


export async function getDataGridLookupList(params: {
    TEMPLETList: string;
    CWBBTXList: string;
    mbTypeList: string;
}) {
    try {


        const paramsData = {
            apis: [
                {
                    name: params.TEMPLETList,
                    // 私用的参数
                    params: {}
                },
                {
                    name: params.CWBBTXList,
                    // 私用的参数
                    params: {}
                },
                {
                    name: params.mbTypeList,
                    // 私用的参数
                    params: {}
                },
            ],
            reload: true,
            // 公用的参数
            params: {}
        }
        const res = await getApisData(paramsData);
        const resTEMPLETList = res.data[params.TEMPLETList]
        const resCWBBTXList = res.data[params.CWBBTXList]
        const resmbTypeList = res.data[params.mbTypeList]
        if (res.ok && resTEMPLETList.ok && resCWBBTXList.ok && resmbTypeList.ok) {
            return Promise.resolve({
                data: res.data,
                success: true,
            });
        }
        return Promise.resolve({
            data: res.data,
            success: false,
        });
    } catch (error) {
        return Promise.resolve({
            data: 'catch,报错了',
            success: false,
        });
    }
}


export async function getZcbfInit(params: {
    zcbfid: string;
    DGMB: string
}) {
    try {
        const res = await getInitData({
            zcbfid: params.zcbfid,
            mbmc: params.DGMB
        });
        if (res.code === 0 && res.ok) {
            return Promise.resolve({
                data: res.data,
                success: true,
            });
        }
        return Promise.resolve({
            data: res.data,
            success: false,
        });
    } catch (error) {
        return Promise.resolve({
            data: 'catch,报错了',
            success: false,
        });
    }
}

export async function updateZcbfPeriod(periodPamas: any) {
    try {
        const res = await getApiData('pm.insertPeriod', periodPamas);
        if (res.ok) {
            return Promise.resolve({
                data: res.data,
                success: true,
            });
        }
        return Promise.resolve({
            data: res.data,
            success: false,
        });
    } catch (error) {
        return Promise.resolve({
            data: 'catch,报错了',
            success: false,
        });
    }
}



export async function delectZcbfPeriod(periodPamas: any) {
    try {
        const res = await getApiData('pm.delectPeriod', periodPamas);
        if (res.ok) {
            return Promise.resolve({
                data: res.data,
                success: true,
            });
        }
        return Promise.resolve({
            data: res.data,
            success: false,
        });
    } catch (error) {
        return Promise.resolve({
            data: 'catch,报错了',
            success: false,
        });
    }
}

export async function initDg(periodPamas: any) {
    try {
        const res = await getNestApiData("/project/initDg", "POST", periodPamas);
        if (res.ok) {
            return Promise.resolve({
                data: res.data,
                success: true,
            });
        }
        return Promise.resolve({
            data: res.data,
            success: false,
        });
    } catch (error) {
        return Promise.resolve({
            data: 'catch,报错了',
            success: false,
        });
    }
}

export async function createDg(periodPamas: any) {
    try {
        const res = await getNestTeApiData("/project", "POST", periodPamas);
        if (res.ok) {
            return Promise.resolve({
                data: res.data,
                success: true,
            });
        }
        return Promise.resolve({
            data: res.data,
            success: false,
        });
    } catch (error) {
        return Promise.resolve({
            data: 'catch,报错了',
            success: false,
        });
    }
}

